/**
 * Created by Administrator on 2017/1/13.
 */
public class Test04 {
    public static void main(String[] args) {
        System.out.println(ReverseSentence(" "));
    }

    public static String ReverseSentence(String str) {
//        String line = "";
//        int index = str.length();
//        char[] chs = str.toCharArray();
//        for (int i = chs.length - 1; i > 0; i--) {
//            if (chs[i] == ' ') {
//                line = line + str.substring(i + 1, index);
//                line += " ";
//                index = i;
//            }
//        }
//        return line += str.substring(0, index);
        String[] strs = str.split(" ");
        String line = "";
        if (strs.length == 0) {
            return str;
        }
        System.out.println(strs.length);
        for (int i = 0; i < strs.length; i++) {
            line = strs[i] + " " + line;
        }
        return line.trim();
    }
}
